package com.network.task;

import com.network.domain.FtpBean;
import com.network.util.BaseData;
import com.network.util.CommonUtils;
import com.network.util.FtpUtils;
import com.network.util.SpringBeanUtil;
import com.network.vo.EquipmentVo;
import org.springframework.beans.factory.annotation.Value;

import java.io.File;
import java.util.Date;

public class FtpUploadTask implements Runnable
{

    private EquipmentVo equipmentVo;

    //ftp目录
    private String path;


    public FtpUploadTask(EquipmentVo equipmentVo) {
        this.equipmentVo=equipmentVo;
    }

    @Override
    public void run()
    {
        synchronized (equipmentVo)
        {

            FtpBean ftpBean=null;
            ftpBean=new FtpBean();

            ftpBean.setHostname(equipmentVo.getIp());
            ftpBean.setUsername(equipmentVo.getUsername());
            ftpBean.setPort(Integer.parseInt(equipmentVo.getPort()));
            ftpBean.setPassword(equipmentVo.getPassword());

            String equipName=equipmentVo.getName();
            String fileType=equipmentVo.getTypename();
            //获取时间
            String timeFile= CommonUtils.formatDateTime("yyyyMMdd",new Date());
            String path= BaseData.basePath +equipName+"/"+fileType+"/"+timeFile;

            FtpUtils ftpUtil= new FtpUtils(ftpBean);
            ftpUtil.setEquipName(equipmentVo.getName());
            ftpUtil.setFileType(fileType);

            String isok="false";
            while ("false".equals(isok))
            {
                isok=ftpUtil.downloadDir(equipmentVo.getFileName(),path,equipmentVo.getFilePath());
            }
            System.out.printf("*********完成");
        }

    }
}
